package com.ruoyi.project.dzbqTask.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.dzbqTask.domain.BasDzbq;
import com.ruoyi.project.dzbqTask.service.IBasDzbqService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电子标签Controller
 *
 * @author zl
 * @date 2024-05-09
 */
@Controller
@RequestMapping("/system/dzbq")
public class BasDzbqController extends BaseController
{
    private String prefix = "system/dzbq";

    @Autowired
    private IBasDzbqService basDzbqService;

    @RequiresPermissions("system:dzbq:view")
    @GetMapping()
    public String dzbq()
    {
        return prefix + "/dzbq";
    }

    /**
     * 查询电子标签列表
     */
    @RequiresPermissions("system:dzbq:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasDzbq basDzbq)
    {
        startPage();
        List<BasDzbq> list = basDzbqService.selectBasDzbqList(basDzbq);
        return getDataTable(list);
    }

    /**
     * 导出电子标签列表
     */
    @RequiresPermissions("system:dzbq:export")
    @Log(title = "电子标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasDzbq basDzbq)
    {
        List<BasDzbq> list = basDzbqService.selectBasDzbqList(basDzbq);
        ExcelUtil<BasDzbq> util = new ExcelUtil<BasDzbq>(BasDzbq.class);
        return util.exportExcel(list, "电子标签数据");
    }

    /**
     * 新增电子标签
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电子标签
     */
    @RequiresPermissions("system:dzbq:add")
    @Log(title = "电子标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasDzbq basDzbq)
    {
        return toAjax(basDzbqService.insertBasDzbq(basDzbq));
    }

    /**
     * 修改电子标签
     */
    @RequiresPermissions("system:dzbq:edit")
    @GetMapping("/edit/{ip}")
    public String edit(@PathVariable("ip") String ip, ModelMap mmap)
    {
        BasDzbq basDzbq = basDzbqService.selectBasDzbqByIp(ip);
        mmap.put("basDzbq", basDzbq);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子标签
     */
    @RequiresPermissions("system:dzbq:edit")
    @Log(title = "电子标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasDzbq basDzbq)
    {
        return toAjax(basDzbqService.updateBasDzbq(basDzbq));
    }

    /**
     * 删除电子标签
     */
    @RequiresPermissions("system:dzbq:remove")
    @Log(title = "电子标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basDzbqService.deleteBasDzbqByIps(ids));
    }
}
